package cn.itcast.solr;

import cn.itcast.solr.pojo.Heima60;
import org.apache.solr.client.solrj.SolrServer;
import org.apache.solr.client.solrj.SolrServerException;
import org.apache.solr.client.solrj.impl.HttpSolrServer;
import org.apache.solr.common.SolrInputDocument;
import org.junit.Test;

import java.io.IOException;

public class IndexCreateTest {

    @Test
    public void createIndex() throws IOException, SolrServerException {
        //创建一个solrServer的连接
        SolrServer solrServer = new HttpSolrServer("http://localhost:8080/solr/core2");


        //文档对象
        SolrInputDocument document = new SolrInputDocument();

        document.addField("id","10086");
        document.addField("title","黑马手机，必定要干翻苹果");
        document.addField("price",1234650);

        solrServer.add(document);

        solrServer.commit();

    }

    @Test
    public void createIndexWithBean() throws IOException, SolrServerException {
        //创建一个solrServer的连接
        SolrServer solrServer = new HttpSolrServer("http://localhost:8080/solr/core2");


        //文档对象
        Heima60 heima60 = new Heima60();
        heima60.setId("10010");
        heima60.setTitle("666手机卡防火防盗");
        heima60.setPrice(123456L);

        solrServer.addBean(heima60);

        solrServer.commit();

    }
}
